using Microsoft.Extensions.Logging;
using TaskScheduler.Core;

namespace TaskScheduler.Tasks;

/// <summary>
/// Hello World 示例任务
/// 这是一个最简单的示例任务，每分钟执行一次
/// </summary>
public class HelloWorldTask : ITask
{
    private readonly ILogger<HelloWorldTask> _logger;

    public HelloWorldTask(ILogger<HelloWorldTask> logger)
    {
        _logger = logger;
    }

    public string TaskName => "HelloWorldTask";
    public string Description => "Hello World 示例任务";
    public bool IsEnabled => true;
    public string CronExpression => "* * * * *"; // 每分钟执行一次

    public async Task<TaskResult> ExecuteAsync(CancellationToken cancellationToken = default)
    {
        try
        {
            _logger.LogInformation("Hello World! 当前时间: {Time}", DateTime.Now);
            
            // 模拟一些工作
            await Task.Delay(100, cancellationToken);

            return new TaskResult
            {
                IsSuccess = true,
                Message = "Hello World 任务执行成功"
            };
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Hello World 任务执行失败");
            return new TaskResult
            {
                IsSuccess = false,
                Message = ex.Message,
                Exception = ex
            };
        }
    }
}

